﻿// 渲染左右各六个框

function renderRegion(marketId) {
    let poultryPie = `<div class="boxall" style="height: 3.2rem">
    <div class="alltitle">禽类销售占比</div>
    <div class="allnav" id="poultryPieEchart"></div>
    <div class="boxfoot"></div>
    </div>`
    $('.poultryPie').html(poultryPie)
    let barcodeMachine = `
    <div class="boxall" style="height: 3.2rem">          
    <div class="alltitle">脚标记状态图</div>
    <div class="allnav" id="barcodeMachineEchart"></div>
    <div class="boxfoot">
    </div> </div>`
    $('.barcodeMachine').html(barcodeMachine)
    let poultryLine = `<div class="boxall" style="height: 3.2rem">
    <div class="alltitle">禽类销量</div>
    <div class="allnav" id="poultryLineEchart"></div>
    <div class="boxfoot"></div>
    </div>`
    $('.poultryLine').html(poultryLine)

    //右侧
    let stallNum = `<div class="boxall" style="height:3.2rem">
    <div class="alltitle">档口数量</div>
    <div class="allnav" id="stallNumEchart"></div>
    <div class="boxfoot"></div>
    </div>`
    $('.stallNum').html(stallNum)
    let relationEchart = `<div class="boxall" style="height: 3.2rem">
    <div class="alltitle">销售去向市场</div>
    <div class="allnav" id="relationEchart"></div>
    <div class="boxfoot"></div>
    </div>`
    $('.relationEchart').html(relationEchart)
    let date = new Date()
    date = date.getMonth() + 1
    let beforeOneMonth = date - 1 <= 0 ? 12 : date - 1
    let beforeTwoMonth = date - 2 <= 0 ? 11 : date - 2
    let poultrySaleTable = `<div class="boxall" style="height: 3.2rem;font-size: -1rem;color: white;">
    <div class="alltitle">近三个月最大销量市场</div>
    <div class="allnav" id="poultrySaleTable">
    <div class="" style="min-height: 0;">
                <table id="tableSell" class="table table-bordered dt-responsive nowrap"
                    style="border-collapse: collapse; border-spacing: 0; width: 100%;background: white;">
                    <thead>
                        <tr>
                            <th>种类</th>
                            <th>${beforeTwoMonth}月</th>
                            <th>${beforeOneMonth}月</th>
                            <th>${date}月</th>
                        </tr>
                    </thead>
                    <tbody id="tableSellBody">
                    </tbody>
                </table>
    </div>
    </div>
    </div>`
    $('.poultrySaleTable').html(poultrySaleTable)
}
//父禽类销售占比饼状图
function poultryPieEchart(marketId) {
    $.ajax({
        url: `${URL}PoultrySales/findSaleOfParent/to/piechart/by/house?houseId=${marketId}`,
        type: 'get',
        dataType: 'json',
        async: false,
        success: (data) => {
            if (data.length == 0) {
                return
            }
            let dataArr = data.object

            dataArr = dataArr.map(item => {
                let obj = {}
                obj.value = item.sale_count
                obj.name = item.poultry_parent_name
                return obj

            })
            console.log(dataArr);
            var myChart = echarts.init(document.getElementById('poultryPieEchart'), 'macarons');
            myChart.clear(); //清除状态
            let option = {
                tooltip: {
                    trigger: 'item',
                    formatter: '{a} <br/>{b} : {c} ({d}%)'
                },
                series: [{
                    name: '销售占比',
                    type: 'pie',
                    radius: '60%',
                    center: ['50%', '60%'],
                    // data:dataArr,原来
                    // 要改
                    data: [{ value: 120, name: "鸡" }, { value: 10, name: "鸭" }, { value: 20, name: "鹅" }, { value: 0, name: "其他" }],
                    // 
                    label: {
                        formatter: '{a|{a}}{abg|}\n{hr|}\n  {b|{b}：}{c}只  ',
                        backgroundColor: '#eee',
                        borderColor: '#aaa',
                        borderWidth: 1,
                        borderRadius: 4,
                        rich: {
                            a: {
                                color: '#999',
                                lineHeight: 22,
                                align: 'center'
                            },
                            hr: {
                                borderColor: '#aaa',
                                width: '100%',
                                borderWidth: 0.5,
                                height: 0
                            },
                            b: {
                                fontSize: 16,
                                lineHeight: 33
                            },
                            per: {
                                color: '#eee',
                                backgroundColor: '#334455',
                                padding: [2, 4],
                                borderRadius: 2
                            }
                        }
                    },
                    labelLine: {
                        lineStyle: {
                            color: 'rgba(255, 255, 255, 0.9)'
                        },
                        smooth: 0.2,
                        length: 10,
                        length2: 20
                    }
                }]
            }

            myChart.setOption(option);
            window.addEventListener("resize", function () {
                myChart.resize();
            });
        }
    })

}
// 脚标机状态雷达图
function barcodeMachineEchart(marketId) {
    $.ajax({
        type: 'GET',
        url: `${URL}MachineChart/find/by/houseId?id=${marketId}`,
        dataType: "json",
        async: false,
        success: function (data) {
            if (data.status !== 0) {
                $('.barcodeMachineEchart').addClass(hidden)
                return
            }
            let dataArr = data.object
            // 原来
            // if (dataArr.length == 0) {
            //     return
            // }
            console.log(dataArr);
            let seriesData = []
            // 原来
            // let indicator = dataArr.map(item => {
            //     seriesData.push(item.size)
            //     return obj = {
            //         text: item.status
            //     }
            // })
            // console.log(indicator);
            // 要改
            let indicator = [
                { text: "离线" },
                { text: "正常" },
                { text: "卡纸" },
                { text: "缺纸" }
            ]
            // 
            let pieData = dataArr.map((cur) => {
                const item = {
                    value: cur.size,
                    name: cur.status
                }
                return item
            })
            var myChart = echarts.init(document.getElementById('barcodeMachineEchart'), 'macarons');
            let option = {
                radar: [{
                    indicator: indicator,
                    center: ['50%', '50%'],
                    radius: 70,
                    startAngle: 60,
                    splitNumber: 4,
                    shape: 'circle',
                    name: {
                        formatter: '{value}',
                        textStyle: {
                            color: '#72ACD1'
                        }
                    },
                    splitArea: {
                        areaStyle: {
                            color: ['rgba(114, 172, 209, 0.2)',
                                'rgba(114, 172, 209, 0.4)', 'rgba(114, 172, 209, 0.6)',
                                'rgba(114, 172, 209, 0.8)', 'rgba(114, 172, 209, 1)'
                            ],
                            shadowColor: 'rgba(0, 0, 0, 0.3)',
                            shadowBlur: 10
                        }
                    },
                    axisLine: {
                        lineStyle: {
                            color: 'rgba(255, 255, 255, 0.5)'
                        }
                    },
                    splitLine: {
                        lineStyle: {
                            color: 'rgba(255, 255, 255, 0.5)'
                        }
                    }

                },],
                series: [{
                    name: '脚标记状态',
                    type: 'radar',
                    emphasis: {
                        lineStyle: {
                            width: 5
                        }
                    },
                    data: [{
                        value: [1, 20, 1, 0],
                        areaStyle: {
                            color: 'rgba(255, 255, 255, 0.5)'
                        },
                        label: {
                            show: true,
                            formatter: function (params) {
                                return params.value;
                            }
                        }
                    }]
                },

                ]
            }
            myChart.setOption(option);
            window.addEventListener("resize", function () {
                myChart.resize();
            });
        },
    })

}
//父禽类销量曲线图
function poultryLineEchart(marketId) {
    $.ajax({
        url: `${URL}PoultrySales/findSaleOfParent/to/linechart?houseId=${marketId}`,
        type: 'get',
        dataType: 'json',
        async: false,
        success: (data) => {
            if (data.status == 1) {
                $('.poultryLine').addClass('hidden')
                return
            }
            if (data.length == 0) {
                return
            }
            let dataArr = data.object
            // 要改
            dataArr.sales_datas = [[14, 37, 85, 1], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]
            console.log(dataArr.sales_datas);
            // 
            months = dataArr.months.map(item => `${item}月`)
            series = dataArr.parents.map((item, i) => {
                return obj = {
                    name: item,
                    type: 'line',
                    stack: '总量',
                    data: dataArr.sales_datas[i],
                }
            })

            var myChart = echarts.init(document.getElementById('poultryLineEchart'), 'macarons');
            myChart.clear(); //清除状态
            option_2 = {
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    show: true,
                    textStyle: {
                        color: '#ffffff'
                    },
                    fontSize: '18',
                    data: dataArr.parents
                },
                grid: {
                    left: '1%',
                    right: '3%',
                    bottom: '1%',
                    containLabel: true
                },
                xAxis: {
                    type: 'category',
                    axisLabel: { //设置字体颜色
                        textStyle: {
                            color: '#fff',
                            fontSize: 12,
                        },
                    },
                    boundaryGap: false,
                    data: months
                },
                yAxis: {
                    name: '只',
                    type: 'value'
                },
                series: series
            };

            myChart.setOption(option_2);
            window.addEventListener("resize", function () {
                myChart.resize();
            });

        }
    })


}
//曲线档口数量
function stallNumEchart(marketId) {
    $.ajax({
        url: `${URL}toMarket/stallsCountByshId?slaughterHouseId=${marketId}`,
        type: 'get',
        dataType: 'json',
        async: false,
        success: (data) => {
            if (data.status == 1) {
                $('.stallNumEchart').addClass('hidden')
                return
            }
            //
            data.length=1
            //要改的
            if (data.length == 0) {
                return
            }
            let dataArr = data.object
            months = dataArr.month.map(item => {
                let [year, month] = item.split('-')
                return `${month}月`
            })
            // 要改
            dataArr.stalls = [35, 35, 35, 35, 35, 35]
            months = ["11月", "12月", "01月", "02月", "03月", "04月"]
            // 
            var myChart = echarts.init(document.getElementById('stallNumEchart'), 'macarons');
            let option = {
                tooltip: {
                    trigger: 'axis'
                },
                grid: {
                    left: '1%',
                    right: '3%',
                    bottom: '5%',
                    top: '5%',
                    containLabel: true
                },
                legend: {
                    show: true,
                    textStyle: {
                        color: '#ffffff'
                    },
                    fontSize: '18',
                    data: months
                },
                xAxis: {
                    type: 'category',
                    axisLabel: {
                        textStyle: {
                            color: '#fff',
                            fontSize: 12,
                        },
                    },
                    type: 'category',
                    data: months
                },
                yAxis: {
                    axisLabel: {
                        interval: 0,
                        textStyle: {
                            color: '#97b0c6',
                        },
                    },
                    type: 'value',
                },
                series: [{
                    data: dataArr.stalls,
                    type: 'line',
                    smooth: true
                }]
            };
            myChart.setOption(option);
            window.addEventListener("resize", function () {
                myChart.resize();
            });
        }
    })

}
//关系图
function relationEchart(marketId) {
    $.ajax({
        type: 'GET',
        url: `${URL}PoultrySales/findRelation/in/year?houseId=${marketId}`,
        dataType: "json",
        async: false,
        success: function (data) {

            if (data.status == 1) {
                $('.relationEchart').addClass('hidden')
                return
            }
            let dataArr = data.object
            if (dataArr.length == 0) {
                return
            }
            // dataArr = dataArr.reduce(function (item, next) {
            //     console.log(item)
            //     obj[next.houseName] ? "" : obj[next.houseName] = true && item.push(next);
            //     console.log(111,obj);
            //     return item;
            // }, []);

            let dataLink = []

            let dataRel = dataArr.map((item, i) => {
                let j = i >= 1 ? 1 : 0
                let size = i >= 1 ? 40 : 70
                let objLink = {
                    source: 0,
                    target: i,
                    value: ''
                }
                dataLink.push(objLink)
                console.log(objLink);
                return objRel = {
                    name: item.houseName,
                    draggable: true, // 是否可以拖拽，默认false
                    category: j, // 这是种类，运维1测试2应用3实施4开发5
                    number: i, // 这是编号 非必须，目的仅为方便编写line
                    value: [30, 5], //图形大小
                    symbolSize: size,
                    showNum: item.saleCount //节点需要显示的额外内容
                }
            })
            console.log(dataRel);
            dataRel = [{ name: "汾江市场", draggable: true, category: 0, number: 0, value: [30, 5], showNum: 590, symbolSize: 70 }, {
                name: "允书白市场", draggable: true, category: 1, number: 2, value: [30, 5], showNum: 11,
                symbolSize: 40
            }, {
                name: "伍乐容市场", draggable: true, category: 1, number: 2, value: [30, 5], showNum: 11,
                symbolSize: 40
            }, {
                name: "佛山市综合批发市场", draggable: true, category: 1, number: 2, value: [30, 5], showNum: 11,
                symbolSize: 40
            }, {
                name: "菅翠丝市场", draggable: true, category: 1, number: 2, value: [30, 5], showNum: 11,
                symbolSize: 40
            }]
            var myChart = echarts.init(document.getElementById('relationEchart'), 'macarons');
            let option = {
                tooltip: {},
                animationDurationUpdate: 1500,
                animationEasingUpdate: 'quinticInOut',
                legend: {
                    x: "center",
                    show: true,
                    data: [] // 此处不显示根节点学生
                },
                series: [{
                    type: 'graph',
                    layout: 'force',
                    symbolSize: function (size) {
                        return size;
                    },
                    edgeSymbol: ['circle', 'arrow'],
                    edgeSymbolSize: [0, 8],
                    edgeLabel: {
                        normal: {
                            show: true,
                            textStyle: {
                                fontSize: 10
                            },
                            formatter: "{c}"
                        }
                    },
                    force: {
                        repulsion: 2500,
                        edgeLength: [1, 5]
                    },
                    focusNodeAdjacency: true,
                    roam: true,
                    categories: [{
                        name: '11',
                    }, {
                        name: '00',
                    }],
                    label: {
                        normal: {
                            show: true,
                            textStyle: {
                                fontSize: 12
                            },
                        }
                    },
                    force: {
                        repulsion: 600
                    },
                    tooltip: {
                        formatter: function (node) { // 区分连线和节点，节点上额外显示其他数字
                            if (!node.value) {
                                return node.data.name;
                            } else {
                                return node.data.name + ":" + node.data.showNum;
                            }
                        },
                    },
                    lineStyle: {
                        normal: {
                            opacity: 0.9,
                            width: 2,
                            curveness: 0.2
                        }
                    },
                    data: dataRel,
                    links: dataLink
                }]
            };

            myChart.setOption(option);
            window.addEventListener("resize", function () {
                myChart.resize();
            });
        },
    })

}
// 市场销售排行表
function initPoultrySaleTable(marketId) {
    $.ajax({
        type: "GET",
        url: `${URL}PoultrySales/findMaxHouse/to/table?houseId=${marketId}`,
        async: false,
        dataType: "json",
        success: function (data) {
            // 要改
            data = {
                "status": 200,
                "msg": "操作成功",
                "object": [{
                    "species": "鸡",
                    "firstSaleHouseOfThreeMonthsAgo": null,
                    "firstSaleHouseOfTwoMonthsAgo": "汾江市场",
                    "firstSaleHouseOfOneMonthAgo": "汾江市场"
                }, {
                    "species": "鸭",
                    "firstSaleHouseOfThreeMonthsAgo": null,
                    "firstSaleHouseOfTwoMonthsAgo": null,
                    "firstSaleHouseOfOneMonthAgo": "汾江市场"
                }, {
                    "species": "鹅",
                    "firstSaleHouseOfThreeMonthsAgo": null,
                    "firstSaleHouseOfTwoMonthsAgo": null,
                    "firstSaleHouseOfOneMonthAgo": "汾江市场"
                }, 
                // {
                //     "species": "飞鸟",
                //     "firstSaleHouseOfThreeMonthsAgo": null,
                //     "firstSaleHouseOfTwoMonthsAgo": null,
                //     "firstSaleHouseOfOneMonthAgo": null
                // }, {
                //     "species": "鱼",
                //     "firstSaleHouseOfThreeMonthsAgo": null,
                //     "firstSaleHouseOfTwoMonthsAgo": null,
                //     "firstSaleHouseOfOneMonthAgo": null
                // }
            ]
            }
            if (data.status == 1) {
                $('.relationEchart').addClass('hidden')
                return
            }
            let tbody = ''
            data = data.object
            if (data.length == 0) {
                alert('该市场暂无禽类销售状态数据')
                return
            }
            for (var i = 0; i < data.length; i++) {
                for (var key in data[i]) {
                    if (data[i][key] == null) {
                        data[i][key] = '';
                    }
                }
                tbody += '<tr class="text-c">' +
                    '<td>' + data[i].species + '</td>' +
                    '<td>' + data[i].firstSaleHouseOfThreeMonthsAgo + '</td>' +
                    '<td>' + data[i].firstSaleHouseOfTwoMonthsAgo + '</td>' +
                    '<td>' + data[i].firstSaleHouseOfOneMonthAgo + '</td>' +
                    '</tr>'
                $("#tableSellBody").html(tbody)
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert('请求禽类销售情况失败')
            $("#poultrySaleTable").html('')
            return
        }
    });
    poultrySaleTable = $('#tableSell').DataTable({
        ordering: false,
        paging: false,
        searching: false
    });
}
// 重建销售排行表
function refreshPoultrySaleTable(marketId) {
    poultrySaleTable.clear(); //销毁datatable
    poultrySaleTable.destroy(); //销毁datatable
    initPoultrySaleTable(marketId) //重新加载数据
}
// 获取省市
function getProvince(province, town) {
    $('#province').val(province)
    $.ajax({
        type: 'get',
        url: `${URL}slaughterHouse/findCity?province=${province}`,
        dataType: 'json',
        success: (data) => {
            // data = data.object
            // if (data.length === 0) {
            //     alert('该市下没有对应的市场')
            //     return
            // }
            data = ['中山市']
            let items = ``
            data.forEach(e => {
                items += `<option value="${e}">${e}</option>`
            })
            $('#town').html(items)
            $("#town").change(() => {
                town = $("#town").val()
                getDistrict(province, town) //调用区
            })
            return getDistrict(province, town)
        },
        error: (data) => {
            alert('获取省份失败')
        }
    })
}
// 获取区
function getDistrict(province, town) {
    let items = ''
    // 要改
    let data=['小榄镇']
    // 原来
    // let data = ['黄圃镇', '南头镇', '东凤镇', '阜沙镇', '小榄镇', '东升镇', '古镇镇', '横栏镇', '三角镇', '民众镇', '南朗镇', '港口镇', '大涌镇', '沙溪镇', '三乡镇', '板芙镇', '神湾镇', '坦洲镇']
    let districtName = data[0] //初始化
    data.forEach(e => {
        items += `<option value="${e}">${e}</option>`
    })
    $('#district').html(items)
    $("#district").change(() => {
        districtName = $("#district").val()
        getMarket(province, town, districtName) //调用区
    })
    getMarket(province, town, districtName)
}
// 省/市/区
function getMarket(province, town, district) {
    $.ajax({
        type: 'get',
        url: `${URL}slaughterHouse/findByDistrict2?province=${province}&city=${town}&district=${district}`,
        dataType: 'json',
        success: (data) => {
            data = data.object
            let marketId = data[0].id //初始化
            let items = ''
            data.forEach(e => {
                items += `<option value="${e.id}">${e.name}</option>`
            })
            $('#market').html(items)
            //取得市场的值交给后台
            $("#market").change(() => {
                marketId = $("#market").val()
                if (!marketId) {
                    return
                }
                renderRegion(marketId)
                poultryPieEchart(marketId)
                poultryLineEchart(marketId)
                barcodeMachineEchart(marketId)
                stallNumEchart(marketId)
                relationEchart(marketId)
                getMapData(marketId)
                refreshPoultrySaleTable(marketId)
                //获取迄今为止
                getNumber(marketId)


            })
            // 初始化表格
            renderRegion(marketId)
            poultryPieEchart(marketId)
            poultryLineEchart(marketId)
            barcodeMachineEchart(marketId)
            stallNumEchart(marketId)
            relationEchart(marketId)
            initPoultrySaleTable(marketId)
            getMapData(marketId)
            getNumber(marketId)
        },
        error: () => {
            alert('请求市场失败')
        }
    })
}


function getMapData(marketId) {
    // 初始化地图
    $.ajax({
        url: `${URL}PoultrySales/findRelation/in/year?houseId=${marketId}`,
        dataType: 'json',
        success: function (data) {
            if (data.status !== 200) {
                alert(data.msg)
                return
            }
            if (!data) {
                alert('暂无数据')
                return
            }
            data = data.object
            // console.log(data);
            data=[
{houseName: "中山市小榄三鸟综合交易中心", saleCount: 590, longitude: "", latitude: ""},
{houseName: null, saleCount: 25, longitude: "null", latitude: "null"},
{houseName: "允书白市场", saleCount: 197, longitude: "113.410343", latitude: "22.556229"},
{houseName: "伍乐容市场", saleCount: 11, longitude: "113.349402", latitude: "22.623499"},
{houseName: "佛山市综合批发市场", saleCount: 101, longitude: "113.300535", latitude: "22.516171"},
{houseName: "菅翠丝市场", saleCount: 236, longitude: "113.500605", latitude: "22.47717"},
{houseName: "中心批发市场", saleCount: 8, longitude: "113.417817", latitude: "22.425865"},
{houseName: "弘韦柔市场", saleCount: 12, longitude: "113.505779", latitude: "22.600545"}]
            let center = data[0] //中心点
            let geoCoordMap = {}
            let myData = data.map((item, i) => {
                geoCoordMap[item['houseName']] = [parseFloat(item.longitude), parseFloat(item.latitude)]
                if (i > 0) {
                    return {
                        name: item.houseName,
                        value: item.saleCount
                    }
                }
            })
            myData.shift()
            map(geoCoordMap, myData, center);
        },
        error: () => {
            // alert('请求地图数据失败')
            //地理位置信息

        }
    })
}


function map(geoCoordMap, myData, center) {
    let uploadedDataURL = 'assets/js/442000_full.json'
    var myChart = echarts.init(document.getElementById('map_1'));
    myChart.showLoading();
    $.getJSON(uploadedDataURL, function (geoJson) {
        echarts.registerMap('china', geoJson);
        myChart.hideLoading();
        var convertData = function (data) {
            var res = [];
            for (var i = 0; i < data.length; i++) {
                var dataItem = data[i];
                var toCoord = geoCoordMap[dataItem.name];
                var fromCoord = [parseFloat(center.longitude), parseFloat(center.latitude)]; //中心地址
                if (fromCoord && toCoord) {
                    res.push([{
                        coord: fromCoord,
                        value: dataItem.value
                    }, {
                        coord: toCoord,
                    }]);
                }
            }
            return res;
        };
        var series = [];
        [
            [center.houseName, myData]
        ].forEach(function (item, i) {
            series.push({
                type: 'lines',
                zlevel: 2,
                effect: {
                    show: true,
                    period: 4, //箭头指向速度，值越小速度越快
                    trailLength: 0.05, //特效尾迹长度[0,1]值越大，尾迹越长重
                    color: '#ffffff',
                    symbol: 'arrow', //箭头图标
                    symbolSize: 6, //图标大小
                },
                lineStyle: {
                    normal: {
                        width: 1, //尾迹线条宽度
                        opacity: 1, //尾迹线条透明度
                        curveness: .3 //尾迹线条曲直度
                    }
                },
                data: convertData(item[1])
            }, //被攻击点
                {
                    type: 'effectScatter',
                    coordinateSystem: 'geo',
                    zlevel: 2,
                    rippleEffect: { //涟漪特效
                        period: 4, //动画时间，值越小速度越快
                        brushType: 'stroke', //波纹绘制方式 stroke, fill
                        scale: 4 //波纹圆环最大限制，值越大波纹越大
                    },
                    label: {
                        normal: {
                            show: false,
                            position: 'right', //显示位置
                            offset: [5, 0], //偏移设置
                            formatter: function (params) { //圆环显示文字
                                return params.data.name;
                            },
                            fontSize: 16,
                            color: "#ffffff"
                        },
                        emphasis: {
                            show: false
                        }
                    },
                    symbol: 'circle',
                    symbolSize: function (val) {
                        return 15; //圆环大小
                    },
                    itemStyle: {
                        normal: {
                            show: false,
                            color: '#f00'
                        }
                    },
                    data: [{
                        name: item[0],
                        value: geoCoordMap[item[0]].concat([10]),
                    }],

                }, {
                type: 'effectScatter',
                coordinateSystem: 'geo',
                zlevel: 2,
                rippleEffect: { //涟漪特效
                    period: 3, //动画时间，值越小速度越快
                    brushType: 'stroke', //波纹绘制方式 stroke, fill
                    scale: 3 //波纹圆环最大限制，值越大波纹越大
                },
                label: {
                    normal: {
                        show: false, //是否显示名称
                        position: 'right', //显示位置
                        offset: [5, 0], //偏移设置
                        formatter: function (params) { //圆环显示文字
                            return params.data.name;
                        },
                        fontSize: 13,
                        color: "#f0f0f0"
                    },
                    emphasis: {
                        show: true,

                        layoutCenter: ['80%', '30%'],
                    }
                },
                symbol: 'circle',
                symbolSize: function (val) {
                    return 8; //圆环大小
                },
                itemStyle: {
                    normal: {
                        show: false,
                        color: '#f00'
                    }
                },
                data: item[1].map(function (dataItem) {
                    return {
                        name: dataItem.name,
                        value: geoCoordMap[dataItem.name].concat([dataItem.value])
                    };
                }),
            },

            );
        });

        option = {
            layoutCenter: ['50%', '40%'],
            // 如果宽高比大于 1 则宽度为 100，如果小于 1 则高度为 100，保证了不超过 100x100 的区域
            layoutSize: 1000,
            tooltip: {
                trigger: 'item',
                formatter: function (params) {
                    if (typeof (params.value)[2] == "undefined") {
                        return params.name + ' : ' + params.value;
                    } else {
                        return params.name + ' : ' + params.value[2];
                    }
                }
            },
            legend: {
                orient: 'vertical',
                y: 'bottom',
                x: 'right',
                data: ['pm2.5'],
                textStyle: {
                    color: '#fff'
                }
            },
            visualMap: {
                show: false,
                min: 0,
                max: 500,
                left: 'left',
                top: 'bottom',
                text: ['高', '低'], // 文本，默认为数值文本
                calculable: true,
                seriesIndex: [1],
                inRange: {

                }
            },

            geo: {
                map: 'china',
                show: true,
                roam: false,
                center: [113.403586328125, 22.475348549488366],
                zoom: 15, //当前视角缩放比例
                label: {
                    normal: {
                        show: false
                    },
                    emphasis: {
                        show: false,
                    }
                },
                itemStyle: {
                    normal: {
                        areaColor: '#3a7fd5',
                        borderColor: '#0a53e9', //线
                        shadowColor: '#092f8f', //外发光
                        shadowBlur: 20
                    },
                    emphasis: {
                        areaColor: '#0a2dae', //悬浮区背景
                    }
                }
            },
            series: series,
        };
        myChart.setOption(option);



        //适配
        window.addEventListener("resize", function () {
            myChart.resize();
        });
    })

}


// 迄今为止，父禽
function getNumber(marketId) {
    $.ajax({
        type: 'get',
        url: `${URL}PoultrySales/findSaleOfParent/by/house?houseId=${marketId}`,
        dataType: 'json',

        success: (data) => {

            if (data.status !== 200) {
                $('#showNumber').addClass('hidden')
                return
            }
            let dataArr = data.object
            if (dataArr.length == 0) {
                return
            }
            console.log(dataArr)
            let str = '迄今为止'
            for (let i = 0; i < dataArr.length; i++) {
                str += `，${dataArr[i].poultry_parent_name}有${dataArr[i].sale_count}只`
            }
            document.getElementById("showNumber").innerHTML = str

        }


    })

}